/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>

#include "sle_connect_server.h"
#include "sle_connect_callback_stub.h"

class SleConnectServerTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;

};
void SleConnectServerTest::SetUp(){}
void SleConnectServerTest::TearDown(){}
void SleConnectServerTest::SetUpTestCase(){}
void SleConnectServerTest::TearDownTestCase(){}

namespace OHOS {
namespace NearLink {
namespace SleStandard {

class SleConnectCallbackStubMock : public SleConnectCallbackStub {
    public:
        void OnConnectStateChange(
            uint16_t connectId, const SleAddress &address, int32_t state, int32_t pairState, uint16_t reason)
            {

            }
        void OnConnectParamUpdateComplete(
            uint16_t connectId, uint16_t interval, uint16_t latency, uint16_t timeout, uint32_t errCode){}
        void OnAuthComplete(
            uint16_t connectId, const SleAddress &address, const SleAuthenticationInfo &info, uint32_t errCode){}
        void OnPairComplete(uint16_t connectId, const SleAddress &address, uint32_t errCode){}
        void OnReadRssiComplete(uint16_t connectId, int8_t rssi, uint32_t errCode){}
};


HWTEST_F(SleConnectServerTest, RegisterConnectCallback_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    EXPECT_EQ(result, SLE_NO_ERROR);
}

HWTEST_F(SleConnectServerTest, UnregisterConnectCallback_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);
    EXPECT_EQ(result, SLE_NO_ERROR);
}

HWTEST_F(SleConnectServerTest, Connect_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);
    SleAddress addrs;
    result = connectServer.Connect(addrs);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, Disconnect_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);
    SleAddress addrs;
    result = connectServer.Disconnect(addrs);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(SleConnectServerTest, GetConnectId_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);
    SleAddress addrs;
    uint16_t connectId = 0;
    result = connectServer.GetConnectId(addrs, connectId);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(SleConnectServerTest, GetConnectState_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);
    SleAddress addrs;
    int32_t state = 0;
    result = connectServer.GetConnectState(addrs, state);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}



HWTEST_F(SleConnectServerTest, GetConnectDeviceList_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);
    std::vector<SleConnectDevice> devices;
    uint16_t number;
    result = connectServer.GetConnectDeviceList(devices, number);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, UpdateConnectParam_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    uint16_t connectId = 0;
    SleConnectionParam param;
    result = connectServer.UpdateConnectParam( connectId, param);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, SendPairRequest_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    SleAddress address;
    result = connectServer.SendPairRequest(  address);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, RemovePairedDevice_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    SleAddress address;
    result = connectServer.RemovePairedDevice(address);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, RemoveAllPairedDevices_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    result = connectServer.RemoveAllPairedDevices();
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, GetPairedDevicesNum_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    uint16_t number ;
    result = connectServer.GetPairedDevicesNum(number);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, GetPairedDevices_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    std::vector<SleAddress> devices;
    uint16_t number;
    result = connectServer.GetPairedDevices(devices, number);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}


HWTEST_F(SleConnectServerTest, GetPairState_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    SleAddress sleaddr;
    uint8_t state;
    result = connectServer.GetPairState(sleaddr, state);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}

HWTEST_F(SleConnectServerTest, ReadRemoteRssi_001, testing::ext::TestSize.Level0)
{
    SleConnectServer connectServer;
    sptr<SleConnectCallbackStubMock> callback = new SleConnectCallbackStubMock;
    int32_t result = connectServer.RegisterConnectCallback(callback);
    result = connectServer.UnregisterConnectCallback(callback);

    uint16_t connectId = 0;
    result = connectServer.ReadRemoteRssi( connectId);
    EXPECT_EQ(result, SLE_ERR_CHECKOUT_FAILED);
}



}}}